package com.bigdatastudio.common.Exception;

import com.bigdatastudio.common.Utils.R;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xiao_jie
 * @date 2022/10/5 16:56
 * @describe  异常处理，捕获异常信息返回到前端
 */

@ControllerAdvice
public class ExceptionAdvice {

//    @ResponseBody
//    @ExceptionHandler(Exception.class)
//    public R handlerException(Exception e){
//        System.out.println(e.getMessage());
//        return R.error("未知错误，请联系管理员");
//    }

    @ResponseBody
    @ExceptionHandler(BadCredentialsException.class)
    public R handler(BadCredentialsException e){
        System.out.println(e.getMessage());
        return R.error("密码错误");
    }

    @ResponseBody
    @ExceptionHandler(CustomException.class)
    public R handlerDeleteException(CustomException e){
        System.out.println(e.getMessage());
        return R.error("失败");
    }

}
